﻿// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

#if SIGNASSEMBLY
[assembly: InternalsVisibleTo("Microsoft.Bot.Streaming.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
#else
[assembly: InternalsVisibleTo("Microsoft.Bot.Streaming.Tests")]
#endif

namespace Microsoft.Bot.Streaming
{
    internal static class StreamExtensions
    {
        /// <summary>
        /// Read the contents of the stream and convert to an Utf8 string.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public static async Task<string> ReadAsUtf8StringAsync(this Stream stream)
        {
            using (var reader = new StreamReader(stream, Encoding.UTF8))
            {
                return await reader.ReadToEndAsync().ConfigureAwait(false);
            }
        }

        /// <summary>
        /// Read the contents of the stream and convert to an Utf8 string.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <returns>Stream contents as string.</returns>
        public static string ReadAsUtf8String(this Stream stream)
        {
            using (var reader = new StreamReader(stream, Encoding.UTF8))
            {
                return reader.ReadToEnd();
            }
        }
    }
}
